<template>
<div v-if='!orderNumber'>订单编号不存在，请刷新重试</div>
<div v-else id="logistics-progress">
    <h3 class="logistics-progress-title">物流进度 - {{orderNumber}}</h3>
    <ul class="time-line-layout">
        <li 
            class='time-line-item' 
            v-for="item in newLogisticsInfo" 
            :key='item.time'
        >
            <div class="logistics-info">
                <p class='logistics-content'>{{item.context}}</p>
                <p class="logistics-time">{{item.time}}</p>
            </div>
        </li>
    </ul>
</div>
</template>

<script>
import { getLogisticsProgress } from '../../config/data'
export default {
    name: 'logisticsProgress',
    props: ['orderNumber'],
    data() {
        return {
            logisticsInfo: []
        }
    },
    created() {
        if(!this.orderNumber) {
            this.$router.push({name: 'orderList'})
        }
        this.getLogisticsProgressInfo()
    },
    methods: {
        async getLogisticsProgressInfo() {
            let result = await getLogisticsProgress({
                lid: 1106975712662 /* this.orderNumber */
            })
            this.logisticsInfo = result.data.info
        }
    },
    computed: {
        newLogisticsInfo() {
            this.logisticsInfo = this.logisticsInfo.map((item, index) => {
                item['tid'] = index
                return item;
            })
            return this.logisticsInfo.sort((a, b) => b.tid - a.tid)
        }
    }
}
</script>

<style scoped>
#logistics-progress {
    height: 100%;
}
.logistics-progress-title {
    overflow: auto;
    height: 50px;
    line-height: 50px;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.time-line-layout {
    overflow: auto;
    display: flex;
    flex-direction: column;
    padding-left: 50px;
    height: calc(100% - 50px);
    box-sizing: border-box;
}
.time-line-layout::-webkit-scrollbar {
    display: none;
}
.time-line-item {
    position: relative;
}
.time-line-item::before {
    content: '';
    position: absolute;
    top: 50%;
    left: -50px;
    width: 8px;
    height: 8px;
    margin-top: -4px;
    border: 1px solid #000;
    background-color: #fff;
    border-radius: 50%;
    z-index: 2;
}
.time-line-item::after {
    content: '';
    position: absolute;
    top: 50%;
    left: -46px;
    width: 2px;
    height: 100%;
    background-color: rgba(133, 133, 133, 0.5);
    z-index: 1;
}
.time-line-item:last-of-type::after {
    display: none;
}
.logistics-info {
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 0 12px;
    border: 1px solid rgba(148, 148, 148, 0.5);
    border-radius: 5px;
    box-shadow: 0 0 5px rgba(148, 148, 148, 0.5);
    margin: 10px 0;
    box-sizing: border-box;
}
.logistics-content {
    display: flex;
    align-items: center;
    width: calc(100% - 12px);
    padding: 12px 0;
    word-break: break-all;
    word-wrap: break-word;
    box-sizing: border-box;
}
.logistics-time {
    height: 32px;
    line-height: 32px;
}
</style>